package com.ly.web.controller.erp;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.AssetsEntity;
import com.ly.heart.service.IAssetsService;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 资产卡片Controller
 *
 * @author cxl
 * @date 2024-09-03
 */
@Api(value = "资产卡片", tags = "资产卡片")
@RestController
@RequestMapping("/heart/Assets")
public class AssetsController extends BaseController {

    @Resource
    private IAssetsService assetsService;

    @Log(title = "暂存资产卡片", businessType = BusinessType.INSERT)
    @PostMapping("/draft")
    @ApiOperation("暂存资产卡片")
    public AjaxResult draft(@RequestBody AssetsEntity assetsEntity){
        return assetsService.draft(assetsEntity);
    }

    @Log(title = "提交资产卡片", businessType = BusinessType.INSERT)
    @PostMapping("/submit")
    @ApiOperation("提交资产卡片")
    public AjaxResult submit(@RequestBody AssetsEntity assetsEntity){
        return assetsService.submit(assetsEntity);
    }

    @Log(title = "修改资产卡片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ApiOperation("修改资产卡片")
    public AjaxResult update(@RequestBody AssetsEntity assetsEntity){
        return assetsService.update(assetsEntity);
    }

    @Log(title = "变更资产卡片", businessType = BusinessType.UPDATE)
    @PostMapping("/change")
    @ApiOperation("变更资产卡片")
    public AjaxResult change(@RequestBody AssetsEntity newAssets){
        return assetsService.change(newAssets);
    }

    @PreAuthorize("@ss.hasPermi('heart:Assets:list')")
    @GetMapping("/list")
    @ApiOperation("查询资产卡片列表")
    public TableDataInfo list(AssetsEntity assetsEntity)
    {
        startPage();
        List<AssetsEntity> list = assetsService.selectAssetsEntityList(assetsEntity);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('heart:Assets:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取资产卡片详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(assetsService.selectAssetsEntityById(id));
    }

    @PreAuthorize("@ss.hasPermi('heart:Assets:remove')")
    @Log(title = "资产卡片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除资产卡片")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(assetsService.deleteAssetsEntityByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('heart:Assets:export')")
    @Log(title = "资产卡片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出资产卡片列表")
    public AjaxResult export(AssetsEntity assetsEntity)
    {
        List<AssetsEntity> list = assetsService.selectAssetsEntityList(assetsEntity);
        ExcelUtil<AssetsEntity> util = new ExcelUtil<AssetsEntity>(AssetsEntity.class);
        return util.exportExcel(list, "Assets");
    }



}
